# 以病人特征信息作为输入，实现MLP进行分类
from keras.models import Sequential
from keras.layers import Dense, Dropout
from keras.optimizers import SGD
from keras.utils import to_categorical
import numpy as np

x_train = np.random.random((100, 20))
y_train = np.random.randint(2, size=(100, 1))
# y_train = to_categorical(np.random.randint(10, size=(1000, 1)), num_classes=10)
x_test = np.random.random((10, 20))
y_test = np.random.randint(2, size=(10, 1))
# y_test = to_categorical(np.random.randint(10, size=(100, 1)), num_classes=10)

model = Sequential()
model.add(Dense(64, activation='relu', input_dim=20))
model.add(Dropout(0.5))
model.add(Dense(64, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(1, activation='sigmoid'))

sgd = SGD(lr=0.01, decay=1e-6, momentum=0.9, nesterov=True)
model.compile(loss='binary_crossentropy', optimizer=sgd, metrics=['accuracy'])
model.fit(x_train, y_train, epochs=1, batch_size=4)

score = model.evaluate(x_test, y_test, batch_size=4)
print(score)